#include "pch.h"
#include "db_tasks.h"
#include "db_interface.h"
#include "threadpool.h"
#include "memorystream.h"

//-------------------------------------------------------------------------------------
bool DBTaskBase::process()
{
	uint64 startTime = TimeUtil::GetMilliSecond();
	
	bool ret = db_thread_process();

	uint64 duration = startTime - initTime_;
	if(duration > 1000)
	{
		LogWarn("DBTask::process(): delay {%u} seconds, try adjusting the kbengine_defs.xml(numConnections) and MySQL(my.cnf->max_connections or innodb_flush_log_at_trx_commit)!\nsql:({%s})\n",
			(uint32)duration, pdbi_->lastquery().c_str());
	}

	duration = TimeUtil::GetMilliSecond() - startTime;
	if (duration > 200)
	{
		LogError("DBTask::process(): took {%u} seconds\nsql:({%s})\n",
			(uint32)duration, pdbi_->lastquery().c_str());
	}

	return ret;
}

//-------------------------------------------------------------------------------------
thread::TPTask::TPTaskState DBTaskBase::presentMainThread()
{
	return thread::TPTask::TPTASK_STATE_COMPLETED; 
}

//-------------------------------------------------------------------------------------
DBTaskSyncTable::DBTaskSyncTable():DBTaskBase("DBTaskSync"),
success_(false)
{
}

//-------------------------------------------------------------------------------------
DBTaskSyncTable::~DBTaskSyncTable()
{
}

//-------------------------------------------------------------------------------------
bool DBTaskSyncTable::db_thread_process()
{
	return false;
}

//-------------------------------------------------------------------------------------
thread::TPTask::TPTaskState DBTaskSyncTable::presentMainThread()
{
	return thread::TPTask::TPTASK_STATE_COMPLETED; 
}

